<template>
  <div class="loginhome" style="overflow: auto">
    <!-- 头部 -->
    <div class="loginheader">
      <span
        class="el-icon-caret-left"
        @click="goback"
        style="cursor: pointer"
      ></span>
      每日推荐
    </div>
    <!-- 主体区域 -->

    <ul class="infinite-list" v-infinite-scroll="load">
      <li
        v-for="(item, index) in daliysongslist"
        :key="index"
        class="infinite-list-item"
        @click="playSong(index)"
      >
        <img :src="item.al.picUrl" class="img" />
        {{ item.name }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      count: 0,
      daliysongslist: [],
    };
  },
  created() {
    this.getDailySongs();
  },
  methods: {
    playSong(index) {
      if (index !== -1) {
        this.$router.push({
          path: "/playsong",
          //携带需要传递的参数
          query: {
            isgetdailysongs: "1",
            index: index,
          },
        });
      }
    },
    load() {
      this.count += 1;
    },
    //   获取每日推荐列表
    getDailySongs() {
      this.axios
        .get(`/recommend/songs`)
        .then((res) => {
          this.daliysongslist = res.data.data.dailySongs;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //   返回按钮返回
    goback() {
      this.$router.push("/home");
    },
  },
};
</script>

<style scoped>
.loginheader {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  color: red;
  border-bottom: red 1px solid;
  height: 30px;
}
.loginDiv {
  margin-top: 200px;
}

.loginDiv .loginNum {
  width: 330px;
  margin-left: 10px;
  background-color: red;
}
.register {
  width: 330px;
  margin-left: 10px;
  margin-top: 20px;
  background-color: red;
}
.img {
  width: 60px;
  height: 60px;
}
.dailydiv {
  display: flex;
}
</style>